import numpy as np

import sys, os
sys.path.append('src/')
import transceiver
import misc


fftlen = 1024
Fs = fftlen/(1./15000)

reps = 2
RBs = np.arange(1,51,1)
CP = True
modsym = 7

ps = misc.PulseShaping(Fs)
cc = misc.Calc()
dh = misc.DataHandling()

EVM = []
EVM01 =[]
for RB in RBs:
    EVM1 = []
    EVM11 = []
    for i1 in range(reps):
        bb = transceiver.Baseband(RB,fftlen)
        fco = 5E6

        x16qam = np.random.randint(0,2,48*RB*modsym)
        xmod,xtemp = bb.ofdm(x16qam,modsym,CP,'16QAM',modout=True,shift=True)
        xmod1,xtemp1 = bb.sc_fdm(x16qam,modsym,CP,'16QAM',modout=True,shift=True)

        xps = ps.rect(xmod,fco)
        xps1 = ps.rect(xmod1,fco)

        ydem = bb.ofdm_dem(xps,modsym,CP)
        ydem1 = bb.sc_fdm_dem(xps1,modsym,CP)

        EVM1 += [cc.EVM(ydem,xtemp)]
        EVM11 += [cc.EVM(ydem1,xtemp1)]
    EVM += [np.mean(EVM1)]
    EVM01 += [np.mean(EVM11)]


dh.write_data(RBs,EVM,'tex/data/evm_o.txt')
dh.write_data(RBs,EVM01,'tex/data/evm_s.txt')



